package com.example.springsecurity.controller;
import com.alibaba.fastjson.JSONObject;
import com.example.springsecurity.mapper.CollegeMapper;
import com.example.springsecurity.service.CollegeService;
import com.example.springsecurity.utils.ResultBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

/**
 * @author lvyongwei + zhangjiahao
 */
@RestController
@RequestMapping(value = "/college")
public class CollegeController {


    @Autowired
    public CollegeService collegeService;

    /**
     * 获取到所有学院信息
     * @return
     */
    @RequestMapping(value = "/getCollege",method = RequestMethod.POST)
    public ResultBean getCollege(){
        return collegeService.getCollege();
    }


    /**
     * 根据学院编号获取专业编号
     * @param getMajor
     * @return
     */
    @RequestMapping(value = "/getMajor",method = RequestMethod.POST)
    public ResultBean getMajor(@RequestBody String getMajor ){
        JSONObject jsonObject=JSONObject.parseObject(getMajor);
        Integer collegeId=jsonObject.getInteger("collegeId");
        return collegeService.getMajor(collegeId);
    }


    /**
     * 获取学院，专业,班级  以及角色信息
     * @return
     */
    @GetMapping("/getGroup")
    public ResultBean getGroup(){
        return collegeService.getCollegeMajorClass();
    }

    /**
     * 根据学院编号来获得项目负责人编号（从教师中选）
     * @param getPrincipal
     * @return
     */
    @RequestMapping(value ="/getPrincipal",method = RequestMethod.POST)
    public ResultBean getPrincipal(@RequestBody String getPrincipal){
        JSONObject jsonObject=JSONObject.parseObject(getPrincipal);
        Integer collegeId=jsonObject.getInteger("collegeId");
        return collegeService.getPrincipal(collegeId);
    }



}
